package cn.fay.chapter16;

import java.util.Arrays;
import cn.fay.chapter15.Generator;

public class ArraySearching {
	public static void main(String[] args) {
		Generator<Integer> gen=new RandomGenerator.Integer(1000);
		int[] a = ConverTo.primitive(Generated.array(Integer.class, gen, 25));
		Arrays.sort(a);
		System.out.println(Arrays.toString(a));
		while (true) {
			int r = gen.next();
			int location = Arrays.binarySearch(a, r);
			if (location>=0) {
				System.out.println("location of "+r+" is "+location+
						", a["+location+"] = "+a[location]);
				break;
			}
		}
	}
}
